package com.naizhuai.ui.dynamic;

import android.content.Context;
import android.support.constraint.Guideline;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.naizhuai.R;
import com.naizhuai.receiver.PushCommonJump;
import com.naizhuai.ui.entity.User.UserNews;
import com.naizhuai.ui.web.WebActivity;
import com.naizhuai.util.ViewUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author：lichenxi
 * @date 2018/4/19 19
 * email：525603977@qq.com
 * Fighting
 */
public class NewListAdapter extends RecyclerView.Adapter<NewListAdapter.Holder> {
   private List<UserNews> result;

    public void setResult(List<UserNews> userNews) {
        result = userNews;
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        View root = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.news_list_item, parent, false);
        return new Holder(root);
    }


    @Override
    public void onBindViewHolder(Holder holder, int position) {
        UserNews news=result.get(position);
        Context context=holder.itemView.getContext();
        ViewUtils.showImg(news.imageUrl,holder.circleImageView);
        holder.article_title.setText(news.title);
        holder.time.setText(news.time);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WebActivity.start(context,news.title,news.jump.viewProperty.url);
            }
        });
    }


    @Override
    public int getItemCount() {
        return result != null ? result.size() : 0;
    }


    static class Holder extends RecyclerView.ViewHolder {
        @BindView(R.id.circleImageView)
        ImageView circleImageView;
        @BindView(R.id.article_title)
        TextView article_title;
        @BindView(R.id.time)
        TextView time;
        Holder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
